<!-- $Id: card_info.htm 14216 2008-03-10 02:27:21Z testyang $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/jquery.min.js,rg_area.js"}
<script type="text/javascript">
var url= "?act=api_area",
	province_id='{if $marketing.id_province}{$marketing.id_province}{else}-1{/if}',
	city_id='{if $marketing.id_city}{$marketing.id_city}{else}-1{/if}',
	dist_id='{if $marketing.id_dist}{$marketing.id_dist}{else}-1{/if}',
	id_store='{if $marketing.id_store}{$marketing.id_store}{else}0{/if}';
</script>
<style type="text/css">
#store_con label{ margin:5px 10px 5px 0; float:left;}
#store_con label input{ margin:0px; vertical-align:middle;}
</style>
<div class="main-div">
<form method="post" action="rg_marketing.php" name="theForm" enctype="multipart/form-data" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">区域</td>
    <td><select onchange="wpxLib.dst(this,0)" name="id_province" id="id_province"><option value="-1">请选择</option>{foreach from=$region_list item=list}<option value="{$list.region_id}"{if $list.region_id == $marketing.id_province} selected{/if}>{$list.region_name}</option>{/foreach}</select>{$lang.require_field}</td>
  </tr>
  <tr>
  	<td class="label">店面</td>
    <td id="store_con"><div style="margin:5px 10px 5px 0;">请选择店铺所对应的地区！</div></td>
  </tr>
  <tr>
    <td class="label">姓名</td>
    <td><input type="text" name="m_name" value="{$marketing.m_name}" />{$lang.require_field}</td>
  </tr>
  <tr>
    <td class="label">身份证号码</td>
    <td><input type="text" name="m_idcard" value="{$marketing.m_idcard}" size="35" />{$lang.require_field}</td>
  </tr>
  <tr>
    <td class="label">地址</td>
    <td><input type="text" name="m_address" value="{$marketing.m_address}" size="35" />{$lang.require_field}</td>
  </tr>
  <tr>
    <td class="label">电话</td>
    <td><input type="text" name="m_moblie" value="{$marketing.m_moblie}" />{$lang.require_field}</td>
  </tr>
{if $form_action == 'insert'}
  <tr>
    <td class="label">营销码</td>
    <td><input type="text" name="code_name" value="{$marketing.code_name}" />{$lang.require_field}</td>
  </tr>
  <tr>
    <td class="label">码值</td>
    <td><input type="text" name="code_fee" value="{$marketing.code_fee}" size="15" />{$lang.require_field}</td>
  </tr>

{else}
  <tr>
    <td class="label">营销码</td>
    <td>{$marketing.code_name} ~ <font color="red">{$marketing.code_fee}</font></td>
  </tr>
{/if}  
  <tr>
    <td>&nbsp;</td>
    <td>
      <input type="submit" class="button" value="{$lang.button_submit}" />
      <input type="reset" class="button" value="{$lang.button_reset}" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$marketing.m_id}" />
      <input type="hidden" name="old_mname" value="{$marketing.m_name}" />
    </td>
  </tr>
</table>
</form>
</div>
{insert_scripts files="../js/utils.js,validator.js"}
{literal}
<script language="JavaScript">
document.forms['theForm'].elements['m_name'].focus();

$(function(){
	startCheckOrder();
	
	if(city_id!='-1'){
		$.getJSON(url+'&id='+province_id+'&level=0',function(data){
			var html=wpxLib.buildSelect('id_city',1,data,city_id,'dst');
			$('#id_province').after(html);
		})
	}
	
	setTimeout(function(){
		if(dist_id!='-1'){
			$.getJSON(url+'&id='+city_id+'&level=1',function(data){
				var html=wpxLib.buildSelect('id_dist',2,data,dist_id,'dst');
				$('#id_city').after(html);
			})
		}
	},5); 
	
	if(dist_id != '-1'){
		$.getJSON("?act=storebydist&id_dist="+dist_id,function(data){
			var store_html='';
			if(data){
				$.each(data,function(i){
					var str=''; if(id_store == data[i].id) str='checked'; 
					store_html+='<label><input type="radio"  id="id_store" name="id_store" value="'+data[i].id+'" '+str+'/>'+data[i].name+'</label>';
				});
			}
			if(store_html == "") $("#store_con").html('<div style="margin:5px 10px 5px 0;">该地区不存在店铺！</div>'); else $("#store_con").html(store_html);
		})
	}
})
	
function validate(){
	var elements = document.forms['theForm'].elements;
	var id_dist = $("#id_dist").val();
	$("#store_con input").each(function(index, element) {
        if($(this).attr("checked")) id_store = $(this).val();
    }); 

    validator = new Validator("theForm");
	if(!id_dist || id_dist == -1) validator.addErrorMsg("请选择正确的区域。"); 
	if(id_store == 0) validator.addErrorMsg("请选择所属店面。"); 
    validator.required("m_name",   '姓名为空，请输入。', 1);
    validator.required("m_idcard",   '身份证为空，请输入。', 1);
    validator.required("m_address",   '地址为空，请输入。', 1);
    validator.isNumber("m_moblie",   '电话为空或者格式不对。', 1);
	
	{if $form_action == 'insert'}
    validator.required("code_name",   '营销码为空，请输入。', 1);
    validator.required("code_fee",   '营销码值为空，请输入。', 1);
	{/if}
	
    return validator.passed();
}
</script>
{/literal}
{include file="pagefooter.htm"}